#define _CRT_SECURE_NO_WARNINGS 1
char* replaceSpaces(char* S, int length) {
    int spaces_count = 0;
    for (int i = 0; i < length; i++)
    {
        if (S[i] == ' ')
        {
            spaces_count++;
        }
    }
    int new_len = length + 2 * spaces_count - 1;
    for (int i = length - 1;i >= 0; i--)
    {
        if (S[i] == ' ')
        {
            S[new_len--] = '0';
            S[new_len--] = '2';
            S[new_len--] = '%';
        }
        else
        {
            S[new_len--] = S[i];
        }
    }
    new_len = length + 2 * spaces_count - 1;
    for (int i = new_len; i >= 0; i--)
    {
        if (S[i] != ' ')
        {
            S[i + 1] = '\0';
            break;
        }
    }
    return S;
}